/*
* Copyright (c) 2009 contentismissing.net, artifacts.de
*
* All rights reserved.
*
* Authors: Jens Lembke <j@contentismissing.net>;
*          Michael Markowski <m.markowski@artifacts.de>;
*
* All non-exclusive rights granted to Deutsche Telekom AG Laboratories
*
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
package net.contentismissing.tlabs.cocktailparty.behaviours
{
	import de.artifacts.multitouch.TouchEvent;
	import de.artifacts.multitouch.behaviours.DragBehaviour;
	import flash.events. * ;
	import net.contentismissing.tlabs.cocktailparty.Constants;
	import net.contentismissing.tlabs.cocktailparty.ui.Bubble;
	public class BubbleTouchBehaviour extends de.artifacts.multitouch.behaviours.DragBehaviour
	{
		public function BubbleTouchBehaviour()
		{
			super();
		}

		/**
		* Diese Funktion wird aufgerufen wenn ein ON TOUCH EVENT ausgelöst wird
		*/
		override public function touchedHandler(event : TouchEvent) : void
		{
			super.touchedHandler(event);
			if (cursor != null && cursor.touchables.indexOf(touchable) == 0)
			{
				(touchable.wrappee as Bubble).onTouch();
			}
		}

		/**
		* Diese Funktion wird aufgerufen wenn ein ON DRAG EVENT ausgelöst wird
		*/
		override public function repositionedHandler(event : TouchEvent) : void
		{
			super.repositionedHandler(event);
			if (cursor != null)
			{
				var evt : Event = new Event(Constants.kEventOnDragBubble);
				(touchable.wrappee as Bubble).dispatchEvent(evt);
			}
		}

		/**
		* Diese Funktion wird aufgerufen wenn ein ON RELEASE EVENT ausgelöst wird
		*/
		override public function releasedHandler(event : TouchEvent) : void
		{
			if (cursor != null)
			{
				if ( !isPositionChanged() && (touchable.wrappee as Bubble)._typ != "phoneBook")
				{
					var evt1 : Event = new Event(Constants.kEventOnDoubleTouchBubble);
					(touchable.wrappee as Bubble).dispatchEvent(evt1);
					(touchable.wrappee as Bubble).onRelease();
				}

				if (isPositionChanged() && (touchable.wrappee as Bubble)._typ != "phoneBook")
				{
					(touchable.wrappee as Bubble).onRelease();
				}

				(touchable.wrappee as Bubble).onRelease();
			}

			cursor = null;
		}
	}
}
